﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Speech.Synthesis;
using System.Threading;
using Newtonsoft.Json.Linq;
using LocalServer.Utils;
using WpfApp2;
using System.Windows.Controls.Primitives;
using Microsoft.Office.Interop.Excel;

namespace LocalServer
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : System.Windows.Window
    {

        delegate void MyDelegate(Object value);

        static int handle = 0;
       public static int Leftcode;
        public static int Rightcode;


        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += Window_Loaded;
            this.Unloaded += Window_UnLoaded;

         
        }
 
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            HttpServer server = App.GetHttpServer();
            if (null != server)
            {
                HttpServer.sendMsgEvent += Client_sendMsgEvent;
            }
            int code = NewIDcardread.Opendevice();//打开读卡设备
            if (code != 1)
            {

                MessageBox.Show("打开设备失败");

            }

        }


        private void Client_sendMsgEvent(Object obj)
        {
            MyDelegate d = new MyDelegate(DealClientMessage);
            this.Dispatcher.Invoke(d, obj);
        }

        private void Window_UnLoaded(object sender, RoutedEventArgs e)
        {
        

          int ret = NewIDcardread.closeID();//关闭读卡器
          
        }
        void DealClientMessage(Object obj)
        {
            
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
            System.Windows.Application.Current.MainWindow.Hide();
        }

      
    }
}
